import user.NormalUser;
import user.AdminUser;
import user.User;
import user.factory.AdminFactory;
import user.factory.IUserFactory;
import user.factory.NormalFactory;
import user.factory.ProxyUser;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘国水
 * Date: 2025-03-30
 * Time: 17:20
 */
public class LibrarySystem {

    public static void main(String[] args) {
        //工厂模式
        IUserFactory adminFactory = new AdminFactory();
        User admin = adminFactory.createUser("刘少", 1);

        IUserFactory normalFactory = new NormalFactory();
        User normal1 = normalFactory.createUser("小蔡",2);
        User normal2 = normalFactory.createUser("卡头",3);

        //代理模式
        ProxyUser proxyUserAdmin = new ProxyUser(admin);
        ProxyUser proxyUserNormal1 = new ProxyUser(normal1);
        ProxyUser proxyUserNormal2 = new ProxyUser(normal2);

        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectProxyRole(proxyUserAdmin,proxyUserNormal1,proxyUserNormal2);

        //打印菜单
        while (true) {
            int choice = currentUser.getRealUser().display();
            //此时⽆需关系是 管理员还是普通⽤⼾，代理类会做权限判断
            currentUser.handleOperation(choice);
        }


        }
    //选择对应⻆⾊进⾏登录
    public ProxyUser selectProxyRole(ProxyUser proxyUserAdmin,
                                     ProxyUser proxyUserNormalW, ProxyUser proxyUserNormalL){

        System.out.println("选择⻆⾊进⾏登录：");
        System.out.println("1.管理员\n2.普通⽤⼾(小蔡)\n3.普通⽤⼾(卡头)\n4.退出系统");
        ProxyUser currentUser = null;
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        switch (choice) {
            case 1:
                currentUser = proxyUserAdmin;
                break;
            case 2:
                currentUser = proxyUserNormalW;
                break;
            case 3:
                currentUser = proxyUserNormalL;
                break;
            case 4:
                System.exit(0);
                System.out.println("系统已退出...");
                break;
            default:
                break;
        }
        return currentUser;
    }

    public static void main1(String[] args) {
        // 直接创建管理员⽤户
        User adminUser = new AdminUser("刘少", 1);
        // 直接创建普通⽤户
        User normalUser1 = new NormalUser("小蔡", 2);
        User normalUser2 = new NormalUser("卡头",3);

    }
}
